//
//  MCOrderPageViewController.swift
//  StoreManage
//
//  Created by MC on 2018/7/4.
//  Copyright © 2018年 MC. All rights reserved.
//

import UIKit

class MCOrderPageViewController: MCPageViewController {
    
    public var activityLogId = 0  // 活动分销记录Id
    
    public var currentPage = 0  // 默认选中第几页
    
    var navBarHairLineImageView : UIImageView?

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        navBarHairLineImageView?.isHidden = true
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        navBarHairLineImageView?.isHidden = false
    }

    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        baseSetting()
        
        initUI()
        
        managerClosure()
        
        sendNetworking()
    }
    
    // MARK: - System Delegate
    
    // MARK: - Custom Delegate
    
    // MARK: - Closure
    func managerClosure() { }
    
    // MARK: - Action
    @objc func leftItemClicked() {
        self.navigationController?.popViewController(animated: true)
    }
    
    @objc func rightItemClikced() {
        let vc = MCOrderSearchViewController()
        MCPushToViewController(current: self, target: vc, isHiddenBottomBarWhenBack: true)
    }
    
    // MARK: - Network
    func sendNetworking() {
        
    }
    
    // MARK: - Method
    func baseSetting() {
        self.title = "订单管理"
        navBarHairLineImageView = MCFindNavigationBarLine(view: (navigationController?.navigationBar)!)
        self.view.backgroundColor = UIColor.white
        
        navigationItem.leftBarButtonItem = MCSetBarButtonItem_image(#imageLiteral(resourceName: "Reuse_back"), target: self, selector: #selector(leftItemClicked),isLeft: true)

        
        navigationItem.rightBarButtonItem = MCSetBarButtonItem_image(#imageLiteral(resourceName: "Reuse_search"), target: self, selector: #selector(rightItemClikced))
        
    }
    
    func initUI() {
        let allArr = [
            ["title":"全部","status":0],
            ["title":"待发货","status":2],
            ["title":"已发货","status":3],
            ["title":"已完成","status":4]
        ]
        let vcArr = NSMutableArray()
        let titleArr = NSMutableArray()
        
        
        for dict in allArr {
            let title = dict["title"] as? String ?? ""
            let status = dict["status"] as? Int ?? 0
            
            titleArr.add(title)
            let vc = MCOrderListViewController()
            vc.closure = { vc in
                MCPushToViewController(current: self, target: vc, isHiddenBottomBarWhenBack: true)
            }
            vc.activityLogId = activityLogId
            vc.isSbuVC = 1
            vc.status = status
            vcArr.add(vc)
        }
        
        
        self.initWithTitleArray(titleArr as! [Any], vcArray: vcArr as! [Any], blockNormalColor: UIColor.MCGray_middle, blockSelectedColor: UIColor.MCMain, currentPage: currentPage)
        
        self.jump(toSubViewController: currentPage)
    }
    
    // MARK: - Setter & Getter
}

